package com.tc168.cp306.b06.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tc168.cp306.b06.MyApplication;
import com.tc168.cp306.b06.R;
import com.tc168.cp306.b06.adaptre.Answer_itemAdapter;
import com.tc168.cp306.b06.bean.Topticbean;
import com.tc168.cp306.b06.gen.TopticbeanDao;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


//答题页面
public class AnswerActivity extends AppCompatActivity {

    @BindView(R.id.back_ig)
    ImageView backIg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.an_rv)
    RecyclerView anRv;

    private List<Topticbean> mdata;
    private Answer_itemAdapter answer_itemAdapter;
    private TopticbeanDao topticbeanDao;
    private int typeaa;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer2);
        ButterKnife.bind(this);

        typeaa = getIntent().getIntExtra("type", 0);
        init();
    }


    private void init() {

        topticbeanDao = MyApplication.getmDaoSession().getTopticbeanDao();
        if (typeaa == 0) {
            title.setText("答案（健康）");
        }
        if (typeaa == 1) {
            title.setText("答案（安全）");
        }
        if (typeaa == 2) {
            title.setText("答案（医药）");
        }
        if (typeaa == 3) {
            title.setText("答案（饮食）");
        }
        if (typeaa == 4) {
            title.setText("答案（生活技巧）");
        }
        if (typeaa == 5) {
            title.setText("答案（趣味知识）");
        }

        mdata = new ArrayList<>();
        answer_itemAdapter = new Answer_itemAdapter(AnswerActivity.this, mdata);

        anRv.setAdapter(answer_itemAdapter);
        anRv.setLayoutManager(new LinearLayoutManager(this));

        answer_itemAdapter.setOnItemClickListener(new Answer_itemAdapter.MyItemClickListener() {
            @Override
            public void onItemClick(View view, int postion) {
                Intent intent = new Intent(AnswerActivity.this, MatterActivity.class);
                intent.putExtra("num", postion);
                intent.putExtra("type", typeaa);
                startActivity(intent);
            }
        });

        List<Topticbean> list = topticbeanDao.queryBuilder().where(TopticbeanDao.Properties.Toptictype.eq(typeaa)).list();
        mdata.addAll(list);
        answer_itemAdapter.notifyDataSetChanged();

    }

    @OnClick(R.id.back_ig)
    public void onViewClicked() {
        finish();

    }
}
